package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.StudentDao;
import com.qfedu.entity.*;
import com.qfedu.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;

    @Override
    public Student findStudentByUno(String u_no) {
        return studentDao.findStudentByUno(u_no);
    }

    @Override
    public int addStudent(Student student) {
        return studentDao.addStudent(student);
    }

    @Override
    public ResponseData<List<Student>> findAllVip(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Student> studentList = studentDao.findAllStudent();
        PageInfo pageInfo = new PageInfo(studentList);
        int count = (int) pageInfo.getTotal();
        ResponseData<List<Student>> responseData = new ResponseData<>();
        responseData.setData(studentList);
        responseData.setCode(0);
        responseData.setCount(count);
        responseData.setMsg("ok");
        return responseData;

    }

    @Override
    public ChartList getStudentBysex() {
        List<SexData> studentBysex = studentDao.getStudentBysex();
        List<String> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        for(SexData sexData : studentBysex){
            list.add(sexData.getSex());
            list1.add(sexData.getNum());
        }
        ChartList chartList = new ChartList();
        chartList.setSexList(list);
        chartList.setNumList(list1);
        return chartList;

    }
}
